package com.pan.cuiniubi.driver;

import com.pan.cuiniubi.create.dao.*;
import com.pan.cuiniubi.entity.DaoInfo;
import com.pan.cuiniubi.entity.Table;
import com.pan.cuiniubi.utils.WriterTool;

import java.util.List;

public class DaoDriver {

    public void outputDao(Table table, CreateDaoMapping createDaoMapping){

        DaoInfo daoInfo = createDaoMapping.getDaoInfo(table);
        String content = createDaoMapping.getDaoContent(daoInfo);
        String myRootPath = System.getProperty("user.dir");
        String daoPath = myRootPath+"\\output\\dao\\"+daoInfo.getClassName()+".java";
        WriterTool.output(daoPath,content);
    }

    public void outputSelectDao(Table table){
        this.outputDao(table,new CreateSelectDaoMapping());
    }
    public void outputSelectDao(List<Table> tables){
        tables.stream().forEach(this::outputSelectDao);
    }

    public void outputDeleteDao(Table table){
        this.outputDao(table,new CreateDeleteDaoMapping());
    }
    public void outputDeleteDao(List<Table> tables){
        tables.stream().forEach(this::outputDeleteDao);
    }

    public void outputUpdateDao(Table table){
        this.outputDao(table,new CreateUpdateDaoMapping());
    }
    public void outputUpdateDao(List<Table> tables){
        tables.stream().forEach(this::outputUpdateDao);
    }

    public void outputInsertDao(Table table){
        this.outputDao(table,new CreateInsertDaoMapping());
    }
    public void outputInsertDao(List<Table> tables){
        tables.stream().forEach(this::outputInsertDao);
    }
}
